home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1974 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  78 lines

  1. Newsgroups: alt.msdos.programmer,comp.lang.c
  2. Path: news.ridgecrest.ca.us!usenet
  3. From: drock@owens.ridgecrest.ca.us (Drock)
  4. Subject: Re: Two C problems
  5. X-Nntp-Posting-Host: annex090
  6. Message-ID: <DLCz57.5wD@ridgecrest.ca.us>
  7. Sender: usenet@ridgecrest.ca.us (Ridgenet Usenet admin)
  8. Organization: RidgeNet - SLIP/PPP Internet, Ridgecrest, CA. (619) 371-3501
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <4cojnn$rgd@lugb.latrobe.edu.au>
  11. Date: Wed, 17 Jan 1996 23:59:00 GMT
  12.  
  13. csigjb@luxor.latrobe.edu.au () wrote:
  14.  
  15.  
  16.  
  17. >This program should exit such that the screen is clear with the DOS prompt
  18. >in the upper left corner, but no, it exits with a short line of text on the
  19. >first line and then the DOS prompt on the next line. I never (or rarely)
  20. >have these sort of problems with Pascal so why do they continuously crop up
  21. >with C.
  22.  
  23. Well, I'm not sure why this happens but there is a couple colutions:
  24.  
  25. The Ugly way:
  26.     Use the borland graphic interface to capture the data on the screen
  27. before anything happens in the program. Then restore the buffer upon
  28. exit. In c++, this can be done using a constructor/destructor. The
  29. only problem is, If you are using Borland, then you have to use their
  30. BGI drivers. THEY SUCK!!!!!!! 
  31.  
  32. The clean way. Write yourself a cool little routine that stores the
  33. contents of the active page. This can be done with a pointer  that is
  34. assigned an absolute address to video memory and treating it as an
  35. array. Then just use the same array to restore what the screen to it's
  36. original status upon exit. look up 
  37.  
  38. >PROBLEM 2 :
  39.  
  40. >const escape=27;
  41. >const cr=13;
  42. >const bs=8;
  43.  
  44. >while (ch!=cr)
  45. >{
  46. >     .
  47. >     .
  48. >     .
  49. >}
  50.  
  51. >while (ch!=escape)
  52. >{
  53. >     .
  54. >     .
  55. >     .
  56. >}
  57.  
  58. >If I replace the 27 with \27' or the 13 with '\13' then these loops don't
  59. >work i.e. an infinite loop results. WHY?
  60.  
  61. >Also if I want to do somthing like this : puts("\24 \25"); which should
  62. >print the up and down arrows on the screen (ASCII 24 and 25), but no, it
  63. >prints some other ASCII characters. As far as I can tell C has its own
  64. >unique character table, at least for the control characters. WHY?
  65.  
  66. >Sometimes I wonder whether some one needs to go back an rewrite the damn
  67. >language so that it works sensibly and predictably like Pascal can be
  68. >relied upon to do.
  69.  
  70. Because when you actually press the esc key, it's ASCII value is 27,
  71. using /27 refers to esc  when using the printf stuff. The /13 is
  72. evaluated in those particular functions but I don';t think they are
  73. evaluated when doing a straight compare. This has happened to me
  74. before. If you do a printf and use /13, you get a CR , but if you read
  75. in a CR, you get 13. Think about it, it's only a byte value and should
  76. be treated as such. 
  77.  
  78.